#include<iostream>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include <arpa/inet.h>  
#include "main.h"
#include "epoll.h"
#include "link.h"

using namespace std;
LINKnode* head=NULL;
int main()
{
   //
   createhead();
    int sockfd=socket(AF_INET,SOCK_STREAM,0);
    if(sockfd<0)
    {
       cout<<"socket fail..."<<endl;
 
    }
    ////
    struct sockaddr_in server;
  server.sin_family=AF_INET;
  server.sin_addr.s_addr=inet_addr(IP);
  server.sin_port=htons(PORT);
  int ret;
  socklen_t len=sizeof(server);
  ret=bind(sockfd,(const  sockaddr *)&server,len);
  if(ret<0)
  {
      cout<<"bind fail!!!!"<<endl;
  }
  ////////
  ret=listen(sockfd,5);
  if(ret<0)
  {
   cout<<"listen fail..."<<endl;

  }
  cout<<"正在监听"<<endl;

  //
  epoll_handle(sockfd);

//
  //
//


   struct sockaddr client;
   socklen_t count=sizeof(client);
   int fd=accept(sockfd,&client,&count);
   if(fd<0)
   {
      cout<<"accept fail ..."<<endl;
      exit(1);
   }

   cout<<"连接成功"<<endl;

  ////
}